Stat 290: Git Mini Tutorial

What is git ?

I am now going to assume you have set up your Git account on GitLab.

Getting Started

Note that the Stanford GitLab website is really under https://code.stanford.edu and https://gitlab.stanford.edu redirects to it a URL on that site.

The credentials business can get a bit involved, so I am not going to discuss later.

Exercise 1: Creation

Goal: Create a repository on Stanford GitLab

These instructions create a project/repository on the remote server. ___

Exercise 1: Cloning

Goal: Clone repository to your local machine.

Exercise 1: Manage in Rstudio

Goal: Associate this directory with Rstudio.

On your local machine, create a new Rstudio project.

You will get something like this. Note the appearance of a Git menu tab on the upper right panel.

Exercise 1: Make changes to README.md

Notice that the display shows one file modified—the M icon, and two other files .gitignore and ex01.Rproj have question marks associated with them: Git is telling you it does not know about those two files, they seem to have appeared from somewhere!

Click on the .gitignore file at the bottom to see what it contains. Mine shows:

This means that these are files that Git will ignore in all its actions.

Exercise 1: Commit

On the Rstudio upper right Git tab you will see subtabs.

Added project to Rstudio and edited README.

Notice that you got a message dialog as below and nothing changes.

Commit always requires a message; make it meaningful in real work.

Exercise 1: Commit (continued)

You must stage your files before committing.

This just commits the changes you made to your local copy of the repository. Commits are groups of edits you want to group as a unit so that you can make sense of them.

What this means is that even if you clobber your files in the repository, you can always get back to the point at which you committed.

(However, nothing prevents you from your machine being corrupted and completely hosing the ex01 folder. Then nobody can help you unless you have a backup. )

Note that a Push button has appeared on the top right. This Push button allows you to push your changes to the remote server, so that there is a record of your commits on the server.

Exercise 02

Goal: To address authentication issues.

  1. In Rstudio, choose Tools -> Global Options -> Git/SVN.

  2. Click on the Create RSA Key button to generate an RSA key. Choose defaults and leave passphrase empty for now.

  3. Remember where Rstudio created the file and open it in Rstudio.

  4. Apply the changes and Rstudio will ask to restart.

  5. On Stanford Gitlab, choose settings

  6. Paste the public key from Rstudio (one line) into the text box. Do not edit, copy as is, into the textbox. Click on the Add key button.

Now you have added an SSH key that makes your identity known to GitLab!

Exercise 02: Commit to remote repo without prompt

Goal: To now commit without being prompted for authentication

On windows, here is how it looks.

At this point, even if your machine were to crash, you can retrieve your complete set of commits from the remote server and go back to any commit.